package com.neusoft.actor.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.neusoft.actor.dto.BedUsageDetailDto;
import com.neusoft.actor.po.BedUsage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BedUsageDao extends BaseMapper<BedUsage> {
    // 在这里可以定义一些自定义的SQL操作（如果有需要）

//    多条件查询床位使用信息，联动客户表和床位表
    @Select("<script>" +
            "SELECT c.client_name, c.client_id, b.room_number, b.bed_number, " +
            "       bu.start_date, bu.end_date, bu.is_current, bu.bed_id, bu.usage_id " +
            "FROM clients c " +
            "JOIN bed_usage bu ON c.client_id = bu.client_id " +
            "JOIN beds b ON bu.bed_id = b.bed_id " +
            "WHERE 1=1 " +
            "<if test='clientName != null and clientName != \"\"'>" +
            "  AND c.client_name LIKE CONCAT('%', #{clientName}, '%') " +
            "</if> " +
            "<if test='admissionDate != null and admissionDate != \"\"'>" +
            "  AND c.admission_date = #{admissionDate} " +
            "</if> " +
            "<if test='isCurrent != null'>" +
            "  AND bu.is_current = #{isCurrent} " +
            "</if> " +
            "</script>")
    List<BedUsageDetailDto> getBedUsageDetailsByConditions(
            @Param("clientName") String clientName,
            @Param("admissionDate") String admissionDate,
            @Param("isCurrent") Boolean isCurrent);
}